<template>
	<!-- 秒杀 -->
	<view class="instantDeath">
		<view class="topBox">
			<view class="left">
				<view class="title">
					限时秒杀
				</view>
				<view class="verticalLine">
					|
				</view>
<!-- 				<view class="subheading">
					距离结束
					<view class="tesuo">
						<view class="item"> 1 </view>
						<view class="item"> 2 </view>
					</view> :
					<view class="tesuo">
						<view class="item"> 0 </view>
						<view class="item"> 1 </view>
					</view> :
					<view class="tesuo">
						<view class="item"> 5 </view>
						<view class="item"> 8 </view>
					</view>
				</view> -->
			</view>
			<view class="right" @click="$goURl('/pages/commodity/seckill/seckill')">
				更多 >
			</view>
		</view>
		<scroll-view scroll-x="true"  class="tabBox" style="white-space: nowrap;display: flex;">
			<view class="tabList" style="white-space: nowrap;display: flex;">
				<view v-for="(item,index) in data.list" :key="index" class="tabItem">
					<view class="title">{{item.name}}</view>
					<view class="tesuo">
						<view class="items" v-for="(items,index) in item.start_time" :key="index">
							{{items}}
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="goodsList">
			<view class="goodsItem" v-for="item in data.goods" :key="item.ID" @click="$goURl('/pages/commodity/seckill/seckillDetails?id='+item.ID)">
				<view class="goodsImage">
					<image :src="item.img" mode=""></image>
				</view>
				<view class="goodsDetail">
					<view class="goodsName textsl2">
						{{item.name}}
					</view>
					<view class="progressBarBox">
						<view class="progressBar" :style="{width:item.buy_number/item.stock*100+'%'}"></view>
						<view class="title">
							已抢  {{item.buy_number/item.stock*100}}%
						</view>
					</view>
					<view class="bottomPrice">
						<view class="left">
							<view class="price">
								￥<text>{{item.money}}</text>
							</view>
							<view class="money">
								￥{{item.market}}
							</view>
						</view>
						<view class="btn">
							立即抢购
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>

</template>

<script setup>  
import { ref, watch, computed, reactive,onMounted,getCurrentInstance } from 'vue';  
const {proxy} = getCurrentInstance();
const props = defineProps({  
  type: {  
    type: Number,  
    default: 1, // 0: 一排3个, 1: 一排4个, 2: 一排5个  
  },  
  list: {  
    type: Array,  
    default: () => []  
  }  
});  
onMounted(()=>{
	killingSession()
})
const data =reactive({
	list:[],
	goods:[],
	current:0,
	page:1,
	size:5
})
	function killingSession(){
		proxy.$request({
			url: `api/killingSession/?page=${1}&size=${20}`,
			method: 'get',
			success(res) {
				data.list=res.data.data
				data.list.forEach(item=>{
					item.start_time =	item.start_time.substring(0, 5)
					item.end_time =	item.end_time.substring(0, 5)
				})
				if(res.data.total!=0){
					data.current=res.data.data[0].ID
					getGoods()
				}
			}
		})
	}
	function getGoods(){
		proxy.$request({
			url: `api/killing/goods_list_all/${data.current}/?page=${data.page}&size=${data.size}`,
			method: 'get',
			success(res) {
				data.goods=res.data.data
			}
		})
	}
</script>

<style lang="scss" scoped>
	.instantDeath{
		margin: 30upx;
		.topBox{
			display: flex;
			justify-content: space-between;
			align-items: center;
			.left{
				display: flex;
				align-items: center;
				.title{
					font-weight: bold;
					font-size: 16px;
					color: #000000;
					line-height: 0px;
					text-align: left;
					font-style: normal;
					text-transform: none;
					margin: 0 10upx;
				}
				.verticalLine{
					color: #909090;
					margin-right: 10upx;
				}
				.subheading{
					font-weight: 500;
					font-size: 12px;
					color: #909090;
					text-align: left;
					font-style: normal;
					text-transform: none;
					display: flex;
				}
			}
			.right{
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 12px;
				color: #909090;
				line-height: 0px;
				text-align: left;
				font-style: normal;
				text-transform: none;
			}
		}
		.tabBox{
			background-color: #FF0034;
			box-shadow: 0px 0px 10px 1px rgba(0,0,0,0.08);
			border-radius: 13px 13px 13px 13px;
			margin-top: 20upx;
			.tabList{
				padding: 10upx;
				.tabItem{
					color: #E6EAED;
					margin-right: 10upx;
					.title{
						width: 100%;
						// padding-left: 5px;
						text-align: center;
						font-weight: bold;
						font-size: 15px;
						color: #FFFFFF;
						font-style: normal;
						text-transform: none;
					}
				}
			}
		}
		.goodsList{
			margin-top: 20upx;
			.goodsItem{
				margin-bottom: 20upx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 10px;
				background: #FFFFFF;
				box-shadow: 0px 0px 10px 1px rgba(0,0,0,0.08);
				border-radius: 13px 13px 13px 13px;
				.goodsImage{
					width: 110px;
					height: 110px;
					image{
						width: 110px;
						height: 110px;
					}
				}
				.goodsDetail{
					width: calc(100% - 120px);
					height: 110px;
					display: flex;
					justify-content: space-between;
					flex-direction: column;
					.goodsName{
						font-weight: bold;
						font-size: 13px;
						color: #000000;
						line-height: 20px;
						text-align: left;
						font-style: normal;
						text-transform: none;
					}
					.progressBarBox{
						width:80%;
						height: 14px;
						background: #EFEFEF;
						border-radius: 7px 7px 7px 7px;
						position: relative;
						.progressBar{
							width: 82px;
							height: 14px;
							background: #FDC4BA;
							border-radius: 7px 7px 7px 7px;
						}
						.title{
							top: -1px;
							left:5px;
							position: absolute;
							font-weight: 500;
							font-size: 10px;
							color: #D51507;
							text-align: left;
							font-style: normal;
							text-transform: none;
						}
					}
					.bottomPrice{
						display: flex;
						justify-content: space-between;
						.left{
							display: flex;
							align-items: flex-end;
							.price{
								font-weight: bold;
								font-size: 10px;
								color: #FF0034;
								text-align: left;
								font-style: normal;
								text-transform: none;
								text{
									font-size: 16px;
								}
							}
							.money{
								margin-left: 5px;
								font-weight: 500;
								font-size: 10px;
								color: #909090;
								text-align: left;
								font-style: normal;
								text-decoration-line: line-through;
								text-transform: none;
							}
						}
						.btn{
							width: 71px;
							height: 26px;
							background: #FF0034;
							border-radius: 13px 13px 13px 13px;
							font-weight: bold;
							font-size: 12px;
							color: #FFFFFF;
							line-height: 26px;
							text-align: center;
							font-style: normal;
							text-transform: none;
						}
					}
				}
			}
		}
	}
	.tesuo{
		display: flex;
		padding-left: 10px;
		margin-right: 5px;
		.item{
			width: 18px;
			height: 18px;
			line-height: 18px;
			color: #fff;
			background-color: #FF0034;
			border-radius: 50%;
			text-align: center;
			margin-left: -5px;
		}
		.items{
			width: 18px;
			height: 18px;
			line-height: 18px;
			color: #FF620C;
			background-color: #FFFFFF;
			border-radius: 50%;
			text-align: center;
			margin-left: -5px;
		}
	}
</style>